home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-11-19 | 4.0 KB | 144 lines | [TEXT/MPS ] |
- /*
- File: LibraryManagerTest1.cp
-
- Contains: xxx put contents here xxx
-
- Copyright: © 1991-1995 by Apple Computer, Inc., all rights reserved.
-
- */
-
-
- #ifndef __STDDEF__
- #include <stddef.h>
- #endif
- #ifndef __STDIO__
- #include <stdio.h>
- #endif
- #ifndef __EVENTS__
- #include <Events.h>
- #endif
- #ifndef THINK_CPLUS
- #ifndef __CURSORCTL__
- #include <CursorCtl.h>
- #endif
- #endif
-
- #ifndef __EXAMPLECLASS__
- #include "ExampleClass.h"
- #endif
-
- static void Idle(RgnHandle);
-
- extern "C"
- void DoTests(TExampleClass* object1, TExampleClass* object2, int count, Boolean trace, Boolean verbose, char* testClassInfoClass)
- {
- RgnHandle myRgn;
- unsigned long endTicks, startTicks;
- unsigned long saveCount = count;
-
- InitGraf(&qd.thePort); // initialize quickdraw so we can use regions
- myRgn = NewRgn(); // a region to use for WaitNextEvent
-
- #ifndef THINK_CPLUS
- InitCursorCtl(NULL);
- #endif
-
- if (object1 && object2)
- {
- startTicks = TickCount();
- object1->SetObjectName("object1");
- object2->SetObjectName("object2");
-
- while (count-- > 0) // <-- here is the test while loop
- { // we put calls to DoThisAndThat in here
- object1->DoThisAndThat(); // here we test DoThisAndThat for object1
- object2->DoThisAndThat(); // here we test DoThisAndThat for object2
- if (trace) Idle(myRgn); // if we are tracing we must idle
- #ifndef THINK_CPLUS
- if (verbose) SpinCursor(1); // if we are verbose we will spin the cursor
- #endif
- }
-
- // test accessing globals
- object1->SetGlobalInt(42); // set the global using object1
-
- // get the global using object2
- // since object1 and object2 share the same A5 world this will return
- // 42!
- if (verbose)
- printf("%s object2->GetGlobalInt() returns: %d\n",object2->GetObjectName(),object2->GetGlobalInt());
-
- // Test the dynamically linked non-virtual member function GetGlobalRef
- long* theGlobal;
- object1->GetGlobalRef(theGlobal);
- // Now theGlobal is the address of a global variable in the example library,
- // whose value should still be 42
- if (verbose)
- printf("Address returned by GetGlobalRef is $%x, value is still %d\n", theGlobal, *theGlobal);
-
- endTicks = TickCount();
- if (verbose)
- printf("Dispatches for %d iterations took %d ticks\n", saveCount, endTicks - startTicks);
-
- // Lets try TExampleClass::Test(char*),
- // note that this is a dynamically linked static member function
- // it will return true since there are 2 instances of TExampleClass
- Boolean hey = TExampleClass::Test("2");
- Boolean hoo = TExampleClass::Test(2);
- Boolean hee = TExampleClass::Test(3);
- if (verbose)
- printf("Three calls to TExampleClass::Test = %s, %s, %s\n",
- (hey ? "true" : "false"), (hoo ? "true" : "false"), (hee ? "true" : "false"));
- }
-
- if (object1)
- {
- if (verbose) printf("Disposing object1\n");
- delete object1;
- }
-
- if (object2) {
- if (verbose) printf("Disposing object2\n");
- delete object2;
- }
-
- // Now its time to really do something
-
- if (testClassInfoClass)
- {
- TClassInfo* theInfo = GetLocalLibraryManager()->GetClassInfo(ClassID(testClassInfoClass));
- if (theInfo)
- {
- do
- {
- char nameBuffer[256]; // for calls to GetVerboseName
- printf("\nClass ID: %s\n", (char*) theInfo->GetClassID());
- printf("flags: NewObject(%s) Preload(%s) FunctionSet(%s)\n",
- theInfo->GetNewObjectFlag() ? "true" : "false",
- theInfo->GetPreloadFlag() ? "true" : "false",
- theInfo->GetFunctionSetFlag() ? "true" : "false");
- printf("version: Version(%04X) MinVersion(%04X)\n",
- theInfo->GetVersion(),
- theInfo->GetMinVersion());
- if (theInfo->GetLibraryFile())
- printf("TLibraryFile: %s\n", theInfo->GetLibraryFile()->GetVerboseName(nameBuffer));
- if (theInfo->GetLibrary())
- printf("TLibrary: %s\n", ((TDynamic*)(void*)theInfo->GetLibrary())->GetVerboseName(nameBuffer));
- if (trace)
- {
- Trace("\nClass ID: %s\n", (char*) theInfo->GetClassID());
- }
- } while (theInfo->Next());
-
- delete theInfo;
- }
- }
- DisposeRgn(myRgn);
- }
-
- static void Idle(RgnHandle myRgn)
- {
- EventRecord myEvent;
- WaitNextEvent(nullEvent, &myEvent, 0, myRgn);
- }
-